<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客发布-达拉崩吧</title>
    <link rel="stylesheet" href="../../static/css/semantic.min.css" th:href="@{/css/semantic.min.css}">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css"
          th:href="@{/lib/editormd/css/editormd.min.css}">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
</head>
<body>

<!--导航-->
<nav th:replace="admin/admin-common :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
</nav>

<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a href="#" th:href="@{/admin/blogs/input}" class="teal active item">发布</a>
            <a href="#" th:href="@{/admin/blogs}" class="item">列表</a>
        </div>
    </div>
</div>

<!--中间内容-->
<div class="m-container-small m-padded-tb-big">
    <div class="ui container">
        <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
            <i class="close icon"></i>
            <div class="header">提示：</div>
            <p th:text="${message}">恭喜，操作成功</p>
        </div>
        <form action="#" id="blog-form" method="post" class="ui form" th:action="${blog?.id}==null ? @{/admin/blogs} : @{/admin/blogs/{id}(id=${blog?.id})}">
            <input type="hidden" name="published">
            <input type="hidden" name="id" th:value="${blog?.id}">
            <div class="required field">
                <div class="ui left labeled input">
                    <div class="ui selection compact teal basic dropdown label">
                        <input type="hidden" name="flag" value="原创" th:value="${blog?.flag}">
                        <i class="dropdown icon"></i>
                        <div class="default text">来源</div>
                        <div class="menu">
                            <div class="item" value="原创">原创</div>
                            <div class="item" value="转载">转载</div>
                            <div class="item" value="翻译">翻译</div>
                        </div>
                    </div>
                    <input type="text" name="title" placeholder="标题" th:value="${blog?.title}">
                </div>
            </div>

            <div class="field">
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea placeholder="博客内容" name="content" style="display: none">[[${blog?.content}]]</textarea>
                </div>
            </div>

            <div class="two fields">
                <div class="field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">分类</label>
                        <div class="ui fluid selection dropdown">
                            <input type="hidden" name="typeId" th:value="${blog?.typeId}">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div class="item" name="typeId" th:each="type : ${types}"
                                     th:attr="data-value=${type?.id}" th:text="${type.name}">分类名称
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui left labeled input">
                        <label class="ui teal basic label">首图</label>
                        <input type="text" name="firstPicture" th:value="${blog?.firstPicture}" placeholder="首图引用地址">
                    </div>
                </div>
            </div>

            <div class="inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend" th:checked="${blog?.recommend}"
                               checked class="hidden">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="shareStatement" name="shareStatement"
                               th:checked="${blog?.shareStatement}" class="hidden">
                        <label for="shareStatement">转载声明</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="appreciation" name="appreciation" th:checked="${blog?.appreciation}"
                               class="hidden">
                        <label for="appreciation">赞赏</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="commentabled" name="commentabled"
                               th:checked="${blog?.commentabled}" class="hidden">
                        <label for="commentabled">评论</label>
                    </div>
                </div>
            </div>

            <div class="required field">
                <textarea name="description" th:text="${blog?.description}" placeholder="博客描述..." maxlength="200"></textarea>
            </div>

            <div class="ui error message" th:value="${message}"></div>

            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button class="ui secondary button" id="save-btn">保存</button>
                <button class="ui teal button" id="publish-btn">发布</button>
            </div>

        </form>
    </div>
</div>

<br>
<br>

<!--底部footer-->
<footer th:replace="admin/admin-common :: footer" class="ui inverted vertical segment m-padded-tb-massive">
</footer>

<script src="../../static/js/jquery-1.7.2.min.js" th:src="@{/js/jquery-1.7.2.min.js}"></script>
<script src="../../static/js/semantic.min.js" th:src="@{/js/semantic.min.js}"></script>
<script src="../../static/lib/editormd/editormd.min.js" th:src="@{/lib/editormd/editormd.min.js}"></script>
<script>

    //初始化Markdown编辑器
    var contentEditor;
    $(function () {
        contentEditor = editormd("md-content", {
            width: "100%",
            height: 640,
            syncScrolling: "single",
            emoji: true,
            // path    : "../static/lib/editormd/lib/"
            path: "[[@{/lib/editormd/lib/}]]"
        });
    });
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'title',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请输入博客标题'
                }]
            },
            typeId: {
                identifier: 'typeId',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请选择博客分类'
                }]
            },
            content: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请输入博客内容'
                }]
            },
            description: {
                identifier: 'description',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请输入博客描述'
                }]
            },
            flag: {
                identifier: 'flag',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请选择博客来源'
                }]
            }
        }
    });

    $('#save-btn').click(function () {
        $('[name="published"]').val(false);
        $('#blog-form').submit();
    });


    $('#publish-btn').click(function () {
        $('[name="published"]').val(true);
        $('#blog-form').submit();
    });



</script>
</body>
</html>